<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>销售订单</title>
<link rel="stylesheet" type="text/css"
	href="../extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="../extjs/ext-all.js"></script>
<script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>
<script>
	Ext.onReady(function(){
	/* 	Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
	    Ext.QuickTips.init(); */
		mainWindow.show();
		
});

	 var store2 = Ext.data.JsonStore({
			fields : []	
		});
	
var fielmenu=new Ext.menu.Menu({
		items:[{text:'历史交易查询',handler:function(){
			windows2.show();	
			
		}},{text:'转单记录查询'},{text:'利润预估查询'},{text:'定金查询'}]
	});
var fielmenu2=new Ext.menu.Menu({
	items:[{text:'转销售出库单'},{text:'销售报价转入',listeners:{
		 'click':function(){ 
			 Ext.Ajax.request({
	    			//被用来向服务器发起请求默认的url   		dangqianriqi biaming lie
	    			url : '/xs_dd/zxsbjd',
	    			//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
	    			params : [{}],
	    			//请求时使用的默认的http方法  
	    			method : "post",
	    			 async:false,
	    			//请求成功时回调函数  
	    			success : function(data) {
	    			  if(data!=null){
	    				  var pp=Ext.decode(data.responseText);
	    				  grids.getStore().add(pp);
	    				  jisui();
	    			  }
	    			},
	    			//请求失败时回调函数  
	    			failure : function() {
	    	 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
	    			}
	    		});
			 
		 }
	}}]
});

var fielmenu4=new Ext.menu.Menu({
	items:[{text:'批次变更单价'},{text:'物料组合设定'},{text:'单况状态设定'}]
});

var page=0;   //页
var totalpage=0;  //总页数


	var fielmenu3=new Ext.menu.Menu({
		items:[{text:'保存',listeners:{  
			 
			 'click':function(){  
				 empt();
				var x1=grids.getStore();
				var tt=Ext.Date.format(Ext.getCmp('billdate').getValue(), 'Y-m-d');
				var data={
				custbillname:Ext.getCmp('custbillname').getValue(),	
				sfhs:Ext.getCmp('sfhs').getValue(),
				billstatus:Ext.getCmp('billstatus').getValue(),
 				billdate:tt,
				billno:Ext.getCmp('billno').getValue(),
				custbillno:Ext.getCmp('custbillno').getValue(),
				custcurrency:Ext.getCmp('custcurrency').getValue(),
				exchrate:Ext.getCmp('exchrate').getValue(),
				salesid:Ext.getCmp('salesid').getValue(),		 
				departname:Ext.getCmp('departname').getValue(),
				maker:Ext.getCmp('maker').getValue(),
				permitter:Ext.getCmp('permitter').getValue(),
				//permittersign:Ext.getCmp('permittersign').getValue(),
				//zje:Ext.getCmp('zje').getValue(),
				//count:Ext.getCmp('count').getValue()    departname
				xs_ddx:Ext.pluck(x1.data.items,"data"),
				};
					alert(JSON.stringify(data));
					 Ext.Ajax.request({
						  url: '/xs_dd/xsddsava', 
						  jsonData:JSON.stringify(data),
						  async:false,
						    success: function(response){ 
						    	alert("xxoo");
						    	
						    }
					 
					 });
					
					
				} 

 
				}},{text:'上一页',listeners:{
					 'click':function(){  
					  if(page==0){
						  alert("最前了！");
					  }else{
						  page--;
						  grids.getStore().removeAll();
						  findAll();
					  }
					
					 }
				}},{text:'下一页',listeners:{
					 'click':function(){  
						  if(page==totalpage){
							  alert("最后了！");
						  }else{
							  page++;
 							  grids.getStore().removeAll();
							  findAll();
						  }
						
						}
				}
			},{text:'删除',listeners:{
				 'click':function(){ 
					 var xsdanhao=Ext.getCmp('billno').getValue(); //单号
					 del(xsdanhao);

					}
			}},{text:'审核',listeners:{
				 'click':function(){ 
					 var qtyremain=0;
					 var xsdh=Ext.getCmp('billno').getValue(); //单号
					 shenhe(xsdh);
					 Ext.each(Ext.pluck(grids.getStore().data.items,'data'), function(obj) {  
						
						
					  qtyremain+=parseInt(obj.qtyremain);
						 alert(qtyremain);
					 });
						 if(qtyremain>0){
							 Ext.Ajax.request({
								  url: '/xs_dd/updatexs?billno='+xsdh+'', 
								  jsonData:JSON.stringify(data),
								  async:false,
								    success: function(response){ 
								       Ext.getCmp('billstatus').setValue("未结案"); //单号
								    }
							 
							 });
							 
						 }else{
							 Ext.Ajax.request({
								  url: '/xs_dd/updatexsx?billno='+xsdh+'', 
								  jsonData:JSON.stringify(data),
								  async:false,
								    success: function(response){ 
								       Ext.getCmp('billstatus').setValue("已结案"); //单号
								    }
							 });
						 }
					}
			}},{text:'反审核',listeners:{
				 'click':function(){ 
					 var xsdh=Ext.getCmp('billno').getValue(); //单号
					 shenhe2(xsdh);

					}
			}},{text:'新建',listeners:{
				 'click':function(){ 
					 empty();
				 
					}
			}},{text:'修改',listeners:{
				 'click':function(){ 
					 emptys();
				 }
			}}]
	});
	
	//禁用
	function empt(){
		formpalcd.items.each(function(f) {
	        f.setReadOnly(true); 
	   });
        formsg.items.each(function(g) {
		    g.setReadOnly(true);
       });
        tbl.disable();
		
	}
	
	
	//修改禁用
	function emptys(){
		formpalcd.items.each(function(f) {
	        f.setReadOnly(false); 
	   });
        formsg.items.each(function(g) {
		    g.setReadOnly(false);
       });
        tbl.enable();
	}
	
	//清空var 
	function empty(){
		Ext.getCmp('form').form.reset();
		Ext.getCmp('form1').form.reset();
		grids.store.removeAll();
		formpalcd.items.each(function(f) {
	        f.setReadOnly(false); 
	   });
        formsg.items.each(function(g) {
		    g.setReadOnly(false);
       });
        tbl.enable();
	}
 
	
	var grids=Ext.create('Ext.grid.Panel',{
		 listeners:{
				containerdblclick: function(){ //双击事件
			    	this.getStore().add({
			    		'Pid':'',
			    		'Pname':'',
			    		'prodsize':'',
			    		'unitname':'',
			    		'squantity':'',
			    		'oldprice':'',
			    		'discount':'',
			    		'sprice':'',
			    		'amount':'',
			    		'taxrate':'',
			    		'taxamt':'',
			    		'vrtotal':'',
			    		'preindate':'',
			    	    'qtyremain':'', 
			    	    'zengpin':'',
			    	    'trantype':'',
			    		'fromno':'',
			    	});				
		    	},cellclick:function(){
 		    		jisui();
		        }
			},plugins: [
	        				Ext.create('Ext.grid.plugin.CellEditing', {
	            				clicksToEdit: 1
	        				})
	    				],
		columns: [
					 {header: '（栏号）',
		                    		xtype: 'rownumberer',
		                    		dataIndex: 'lh', 
		                    		width: 50,
									sortable: false
	        					},
	        				
	        		{ header: '物料编号',  dataIndex: 'Pid', width: 100,editor:{xtype:'textfield',
	        		 	listeners:{
							focus:function(grid, e, eOpts){
									windows2.show();
									}
						}
	        		}},
	       			 { header: '物料名称', dataIndex: 'Pname',width: 120,editor: { xtype:'textfield',
					 	listeners:{
							focus:function(grid, e, eOpts){
									windows2.show();
									}
	        	 
						}
					 } },     
		
					     { header: '详表id', dataIndex: 'prodid',hidden: true},
					     { header: '详表名称', dataIndex: 'prodname',hidden: true},
	       				 { header: '规格型号', dataIndex: 'prodsize',editor:"textfield" },
						 { header: '单位名称', dataIndex: 'unitname' ,editor:"textfield" },
						 { header: '数量', dataIndex: 'squantity',editor:"textfield" },
						 { header: '折扣前单价', dataIndex: 'oldprice',editor:"textfield"  },
						 { header: '折数(%)', dataIndex: 'discount',editor:"textfield"  },
						 { header: '单价', dataIndex: 'sprice' ,editor:"textfield" },
						 { header: '金额', dataIndex: 'amount',editor:"textfield"  },
						 { header: '税率', dataIndex: 'taxrate',editor:"textfield"  },
						 { header: '税额', dataIndex: 'taxamt' ,editor:"textfield" },
						 { header: '含税金额', dataIndex: 'vrtotal' ,editor:"textfield" },
						 { header: '预出库日', dataIndex: 'preindate' ,editor:"textfield" },
						 { header: '未出数量', dataIndex: 'qtyremain' ,editor:"textfield" },
						 { header: '赠品', dataIndex: 'zengpin',editor:"textfield" },
						 { header: '来源单别', dataIndex: 'trantype',editor:"textfield" },
						 { header: '来源单号', dataIndex: 'fromno' ,editor:"textfield" },
	   					 ],
	   			 height: 130,
				 width:1971,
				 autoScroll:false,
				 
	});
	
	
	var form2=Ext.create('Ext.form.Panel', {
	    bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[{
			 xtype: 'textfield',
	        name: 'SalesMan',
			bodyPadding: 5,
	        fieldLabel: '账款归属',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				},{
			 xtype: 'datefield',
	        name: 'Marker',
	        format:'Y-m-d',
	        fieldLabel: '付款日期',
			style:'margin-left:19px',
			value:Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH,0),"Y-m-d"),
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				},
			{
			xtype: 'combobox',
	        name: 'Marker',
	        fieldLabel: '付款条件',
			width:250,
			valueField: 'abbr',
			displayField:"abbr",
	        labelWidth: 80,
	        anchor: '100%',
	        valueField: 'abbr',
			store: Ext.create('Ext.data.Store', {
				fields: ['abbr', 'name'],
				data : [
					{"abbr":"货到", "name":"货到"},
					{"abbr":"次月", "name":"次月"},
					{"abbr":"月结", "name":"月结"},
					{"abbr":"其他", "name":"其他"}
			   ]
			}),
			value: '货到',
			typeAhead: true,
			mode: 'local',
			triggerAction: 'all',
			selectOnFocus:true,
			},{
			xtype: 'datefield',
	        name: 'ProdDepart',
	        fieldLabel: '账款月份',
			style:'margin-left:19px',
			 value:Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH,0),"Y-m-d"),
			format:'Y-m',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				}],
		});
		var ppa2 = Ext.create('Ext.panel.Panel', {
	    bodyPadding: 6,  // 避免Panel中的子元素紧邻边框
	    width: 600,
		height:170,
		items:form2
	});

	var ppa = Ext.create('Ext.panel.Panel', {
	    bodyPadding: 6,  // 避免Panel中的子元素紧邻边框
	    width: 1985,
		height:170,
	    items:[grids], 
		bbar:[{xtype:"label",text:'总计:',width:90},
		{xtype:"textfield",id:"number",disabled:true,width:90,margin:'0 180',value:'0.00'},
		{xtype:"textfield",id:"jine",disabled:true,width:90,margin:'0',value:'0.00'},
		{xtype:"textfield",id:"suie",disabled:true,width:90,margin:'0 40 0 30',value:'0.00'},
		{xtype:"textfield",id:"hansuijine",disabled:true,width:90,margin:'0 0 0 0',value:'0.00'}]
	});

	
	var  tbl=Ext.create('Ext.TabPanel',{
		width:"100%",
		height:230,
		autoScroll:true,
		bodyPadding: 5,
		items:[{title:'内容',autoScroll:true,items:[ppa]},{title:'账款',autoScroll:true,items:[ppa2]},{title:'备注',xtype:'textarea',name:'Remark',fieldLabel: '备注',labelWidth: 30,}]
	});

	var formsg=Ext.create('Ext.form.Panel', {
		id:'form1',
	    bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[{
			id:'salesid',
			xtype: 'textfield',
	        name: ' salesid',
			bodyPadding: 5,
	        fieldLabel: '业务人员',
	        style:'color:blue',
			width:250,
	        labelWidth: 80,  
	        anchor: '100%',
				},{
			id:'maker',
			xtype: 'textfield',
	        name: 'maker',
	        fieldLabel: '制单人员',
			style:'margin-left:19px',
			width:250,
	        labelWidth: 80,
	        value:'Admin',
	        anchor: '100%',
				},{
		    id:'departname',
			xtype: 'textfield',
	        name: 'departname',
	        style:'color:blue',
	        fieldLabel: '所属部门',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				},{
		     id:'permitter',
			 xtype: 'textfield',
	        name: 'permitter',
	        fieldLabel: '复核人员',
			style:'margin-left:19px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				},{
		    id:'prodproject',
			xtype: 'textfield',
	        name: 'prodproject',
	        fieldLabel: '所属项目',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				}],
		});


var formpalcd=Ext.create('Ext.form.Panel', { //表单
	id:'form',
	bodyPadding: 5,
    width:'100%',
    // 将会通过 AJAX 请求提交到此URL
//      url: '/xs_dd/selxsdd',
    // 表单域 Fields 将被竖直排列, 占满整个宽度
    layout: 'column',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
    	    id:'custbillname',
			xtype: 'textfield',
       		name: 'custbillname',
       		style:'color:blue',
			fieldLabel: '客户编号',
       		labelWidth: 70
       		
			},{
		id:'billdate',
		style:'margin-left:9px;color:blue',
		xtype: 'datefield',
        name: 'billdate',
        fieldLabel: '单据日期',
        format:'Y-m-d',
        value:Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH,0),"Y-m-d"),     
        listeners: {
       	 "blur": function() {
        	//	 alert(Ext.util.Format.date(Ext.getCmp('billdate').getValue()),"Y-m-d")+"好好");
         	alert(Ext.Date.format(Ext.getCmp('billdate').getValue(), 'Y-m-d'));	
			bdate(Ext.Date.format(Ext.getCmp('billdate').getValue(), 'Y-m-d'));
        }
       },
        labelWidth: 70,
        anchor: '100%',
		},{
			id:'custaddress',
		xtype: 'textfield',
        name:'custaddress',
        fieldLabel: '送货地址',
        labelWidth: 70,
        width:160,
        anchor: '100%',
		},{
			id:'supplierFullName',
		xtype: 'textfield',
        name:'supplierFullName',
        width:66,
        labelWidth: 70,
        anchor: '100%',
		},{
	    id:'billno',
	    style:'margin-left:9px;color:blue',
		xtype: 'textfield',
        name: 'billno',
        fieldLabel: '单据号码',
        labelWidth: 70,
// 		vtype:'url',//只能输入网址
        anchor: '100%',
			},{
	    id:'supplierSimName',
		xtype: 'textfield',
        name: 'supplierSimName',
        fieldLabel: '订单类型',
        labelWidth: 70,
		regex:/^[\u4E00-\u9FA5]+$/,//自定义正则表达式,(只能输入汉字);
		regexText:'叫你输入汉字啊,SB吗？',//提示
        anchor: '100%',
			},{
	    id:'custcurrency',
		style:'margin-left:9px;color:blue',
		xtype: 'textfield', //多行文本域
        name: 'custcurrency',
        fieldLabel: '币别',
        labelWidth: 70,
        value:'人民币',
        anchor: '100%',
			},{
				id:'sfhs',
		 xtype: 'combo',
        fieldLabel: '单价含税',
     
// 		regex:/^[A-Za-z]+$/,//自定义正则表达式,(只能输入汉字);
// 		regexText:'叫你输入英文列啊,SB吗？',//提示
        labelWidth: 70,
        displayField:"sfhs",  
        anchor: '100%',
    	valueField: 'sfhs',
		store: Ext.create('Ext.data.Store', {
			fields: ['sfhs', 'name'],
			data : [
				{"sfhs":"含税", "name":"含税"},
				{"sfhs":"未税", "name":"未税"}
				
		   ]
		}),
		value: '未税',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
			},{
		id:'exchrate',
	    style:'margin-left:9px',
		xtype: 'textfield',  //数值
        name: 'exchrate',
        fieldLabel: '汇率',
        labelWidth: 70,
        anchor: '100%'
        },{
        id:'billstatus',
   		xtype: 'combo',
        fieldLabel: '单况',
//  		regex:/^[A-Za-z]+$/,//自定义正则表达式,(只能输入汉字);
        labelWidth: 70,
        anchor: '100%',
        displayField:"billstatus",   
        valueField: 'billstatus',
		store: Ext.create('Ext.data.Store', {
			fields: ['billstatus', 'name'],
			data : [
				{"billstatus":"已结案", "name":"已结案"},
				{"billstatus":"未结案", "name":"未结案"}
		   ]
		}),
 		value: '未结案',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
 		},{
 		 id:'custbillno',
 	     style:'margin-left:9px',
 		 xtype: 'textfield',  //数值
         name: 'custbillno',
         fieldLabel: '客户订单',
         labelWidth: 70,
         anchor: '100%'
         },{
     		 id:'ches',
     		 hideLabels:true,
     		 checkboxToggle:true,
     	     style:'margin-left:9px',
     		 xtype: 'checkbox',  //数值
             boxLabel: '保存',
             items:[{boxLabel:"保存",inputValue:1,checked:true}]
         }]
    
});



//反审核
function shenhe2(xsdh){
	  Ext.Ajax.request({
			//被用来向服务器发起请求默认的url   		dangqianriqi biaming lie
			url : '/xs_dd/sh2?billno='+xsdh+'',
			//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
			params : [{}],
			//请求时使用的默认的http方法  
			method : "post",
			 async:false,
			//请求成功时回调函数  
			success : function(data) {
			if(data!=null){
				alert("成功！");
			}
			},
			//请求失败时回调函数  
			failure : function() {
	 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
			}
		});
	  
}

  //审核
  function shenhe(xsdh){
	  Ext.Ajax.request({
			//被用来向服务器发起请求默认的url   		dangqianriqi biaming lie
			url : '/xs_dd/sh?billno='+xsdh+'',
			//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
			params : [{}],
			//请求时使用的默认的http方法  
			method : "post",
			 async:false,
			//请求成功时回调函数  
			success : function(data) {
			if(data!=null){
				alert("成功！");
			}
			},
			//请求失败时回调函数  
			failure : function() {
	 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
			}
		});
	  
  }


//日期
function bdate(billdt){
	Ext.Ajax.request({
		//被用来向服务器发起请求默认的url   		dangqianriqi biaming lie
		url : '/xs_dd/danhao?dh='+billdt+'',
		//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
		params : [{}],
		//请求时使用的默认的http方法  
		method : "post",
		 async:false,
		//请求成功时回调函数  
		success : function(data) {
		 var pp=Ext.decode(data.responseText);
 	     Ext.getCmp('billno').setValue(pp);
		},
		//请求失败时回调函数  
		failure : function() {
 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
		}
	});

}
    
    //删除
      function del(xsdanhao){
    		Ext.Ajax.request({
    			//被用来向服务器发起请求默认的url   		dangqianriqi biaming lie
    			url : '/xs_dd/delxsddx?xsdd='+xsdanhao+'',
    			//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
    			params : [{}],
    			//请求时使用的默认的http方法  
    			method : "post",
    			 async:false,
    			//请求成功时回调函数  
    			success : function(data) {
    			  if(data!=null){
    				  alert("成功！");
    				  findAll();
    			  }
    			},
    			//请求失败时回调函数  
    			failure : function() {
    	 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
    			}
    		});
    	  
      }
      
      
   
function findAll() {
	//var song=Ext.encode(forms.getForm().getValues());
	Ext.Ajax.request({
		//被用来向服务器发起请求默认的url  
		url : "/xs_dd/selxsdd?pagesize="+page+"",
		//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
		params : [{}],
		//请求时使用的默认的http方法  
		method : "post",
		//请求成功时回调函数  
		success : function(data) {
		 var pp=Ext.decode(data.responseText)
		 totalpage=pp.totalsize;
// DepartName	ProdID ProdName	 alert(JSON.stringify(pp));billno  custbillid custbillname
            Ext.getCmp('custbillname').setValue(pp.list[0].custbillname);
            Ext.getCmp('billno').setValue(pp.list[0].billno);
			Ext.getCmp('custbillno').setValue(pp.list[0].custbillno);
			Ext.getCmp('exchrate').setValue(pp.list[0].exchrate);
			Ext.getCmp('custcurrency').setValue(pp.list[0].custcurrency);
			Ext.getCmp('supplierSimName').setValue(pp.list[0].supplierSimName);
// 			Ext.getCmp('textfield').setValue(pp.textfield);
			Ext.getCmp('custaddress').setValue(pp.list[0].custaddress);
			Ext.getCmp('billdate').setValue(pp.list[0].billdate);
			Ext.getCmp('prodproject').setValue(pp.list[0].prodproject);
			Ext.getCmp('salesid').setValue(pp.list[0].salesid);
			Ext.getCmp('departname').setValue(pp.list[0].departname);
			Ext.getCmp('maker').setValue(pp.list[0].maker);
			Ext.getCmp('permitter').setValue(pp.list[0].permitter);
			grids.getStore().add(pp.list[0].xs_ddx);
 			//billstatus Ext.ux.Toast.msg("信息提示", "成功删除所选记录！"); departname maker permitter
			jisui();
			
			formpalcd.items.each(function(f) {
				        f.setReadOnly(true); 
				   });
			formsg.items.each(function(g) {
					    g.setReadOnly(true);
			});
			 tbl.disable();
 
  		},
		//请求失败时回调函数  
		failure : function() {
 			Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
		}
	});
}


var btn2=Ext.create("Ext.Button", {
    text: "取回",
    width:70,
    height:24,
    listeners: { "click": function () {
    var row = Ext.getCmp("grids2").getSelectionModel().getLastSelected(); 
    /* var record = grids2.getSelectionModel().getLastSelected(); */
    
    	if(record.length==0){
    		 Ext.Msg.alert("提示信息", "您没有选中行!");  
    	}
    	else{
    		 Ext.Msg.alert("提示信息", "您选中了此行!"); 
    		 alert(record.billno);
          		 
    	}
    }
    },
    id: "btn",
});	




var grids2=Ext.create('Ext.grid.Panel',{ 
	id:'grids2',
	name:'grids2',
	listeners:{
		'itemdblclick' : function(grid, rowIndex, e,i){
			var bino=grid.store.getAt(i).get('billno');
			ddzr(bino);
			windows2.hide();
		}  		
    },
	columns: [
		{header: '（栏号）',
			
	     xtype: 'rownumberer',
	     dataIndex: 'grids2', 
	     width: 58,
		 sortable: false
        },
        { header: '销售订单单号',  dataIndex: 'billno', width: 96},
        { header: '订单类型',  dataIndex: 'trantype', width: 96},
        { header: '订单日期',  dataIndex: 'billdate', width: 96},
        { header: '币别',  dataIndex: 'custcurrency', width: 96},
        { header: '单价是（是否含税）',  dataIndex: 'sfhs', width: 96},
        { header: '物料编号',  dataIndex: 'prodid', width: 96},
        { header: '物料名称',  dataIndex: 'prodname', width: 96},
        { header: '数量',  dataIndex: 'squantity', width: 96},
        { header: '（折扣前单价）',  dataIndex: 'oldprice', width: 96},
        { header: '（折数%）',  dataIndex: 'billdate', width: 96},
        { header: '单价',  dataIndex: 'sprice', width: 96},
        { header: '金额',  dataIndex: 'amount', width: 96}
        
        ],
   	store:store2,
   	width:349,
   	height: 240,
	autoScroll:true,				 
})

 
//历史交易查询
var windows2=new  Ext.Window({
	width:360,
	height:300,
	title:"历史记录查询",
	closable:true,
	resizable:false, //设置是否可以改变大小
	draggable:true,
	anchor: '100%',
	items:[grids2,btn2],
	listeners: {
		activate : function() {	
			Ext.Ajax.request({
				url:"/xs_dd/queryxsdd",
				params :{},
				method : "post",
				async: false,
				success : function(data){
					var de=Ext.JSON.decode(data.responseText);
					grids2.getStore().loadData(de);
				},
				failure : function(){
					
				}
			});
    	}
	 } 
});


function jisui(){
	var number=0;
	var jine=0.00;
	var suie=0.00;
	var hansuijine=0.00;  
	Ext.each(Ext.pluck(grids.getStore().data.items,'data'), function(obj) {  
		number+=parseInt(obj.squantity);
		jine+=parseFloat(obj.amount);
		suie+=parseFloat(obj.taxamt);
		hansuijine+=parseFloat(obj.vrtotal);
    });
 
	Ext.getCmp('number').setValue(number);
	Ext.getCmp('jine').setValue(jine);
	Ext.getCmp('suie').setValue(suie);
	Ext.getCmp('hansuijine').setValue(hansuijine);
}


var mainWindow = new Ext.Window({

		width:640,
		height:550,
		title:"销售订单",
		closable:true,
		resizable:false, //设置是否可以改变大小
		draggable:true, //设
		items:[formpalcd,tbl,formsg],
		listeners : {
			activate : function() {
				
				findAll();
// 				bdate("");
			}
		},
		bbar:[{xtype:"splitbutton",text:'查询',width:90,menu:fielmenu},{xtype:"splitbutton",text:'转单',width:90,menu:fielmenu2},{xtype:"splitbutton",text:'搞业务',width:90,menu:fielmenu3},{xtype:"splitbutton",text:'功能',width:90,menu:fielmenu4}],
	});

function fromaction(){
	alert(Ext.encode(formpalcd.getForm().getValues()));// 序列化表单
}

</script>
</head>

<body>
</body>
</html>
